Page({
  data: {
    loading: true,
    resultList:[],
    topicScore:'',// 只显示单个对象
    topicTime:'',
    reportLevel: '',
    topicConclusion:'',
    suggestions: [],
    testId:'',
    // userId:''
  },

  onLoad(options) {
    console.log('options',options);
    // const app = getApp();
    // console.log('app.globalData.loginUserInfo',app.globalData.loginUserInfo); 
    this.setData({
      testId:options.testId,
      // userId:app.globalData.loginUserInfo.id
    })
    this.loadResult(this.data.testId);
  },

  loadResult(testId) {
    
    wx.request({
      // &userId=${userId}
      url: `http://localhost:8080/topicResult/pages?psyknoTest=${testId}`,
      method: 'GET',
      success: (res) => {
        console.log('res',res);
        // 假设返回的就是你给的对象结构
        if (res.data && res.data.code === 200 && res.data.data) {
          const result = res.data.data.list;
          // 这里可以根据分数自定义等级
          let reportLevel = '';
          if (result.topicScore >= 80) {
            reportLevel = '优秀';
          } else if (result.topicScore >= 60) {
            reportLevel = '良好';
          } else if (result.topicScore >= 40) {
            reportLevel = '一般';
          } else {
            reportLevel = '重点关注';
          }
          // 建议可以写死或后端返回
          const suggestions = [
            '建议多与家人朋友沟通',
            '保持良好作息',
            '如有需要可寻求专业帮助'
          ];
          this.setData({
            resultList: result,
            reportLevel,
            suggestions,
            loading: false,
          });
          console.log('resultList',this.data.resultList);
        } else {
          this.setData({ loading: false });
        }
      },
      fail: (err) => {
        console.error('获取结果失败:', err);
        this.setData({ loading: false });
      }
    });
  },

  saveReport() {
    wx.showToast({ title: '保存成功', icon: 'success' });
  }
});